/**
* @program: src
*
* @description:消息处理控制器
*
* @author: Mr.chen
*
* @create: 2020-12-07 11:23
**/
package message

import (
	"ydd-im/service/api/services/wsservice/message"
	"ydd-im/service/api/services/wsservice/account"
	"ydd-im/service/api/tools/bind"
	"ydd-im/service/api/tools/response"
	"github.com/gin-gonic/gin"
)

type Controller struct {
}
type inputData struct {
	MessageType int `json:"messageType" form:"messageType" binding:"gte=0,lte=1" ` // 消息类型，1私聊，0群聊
}

// 获取签名相关的所有用户
func (r *Controller) GetMessageHistoryLog(c *gin.Context) {
	var inputData inputData
	_, err := bind.Bind(&inputData, c)
	if err != nil {
		response.ResponseJsonFail(c, response.Response{
			Code:    response.ErrorCode,
			Message:"参数有误，请重试",
		})
		return
	}
	// 获取用户信息
	userInfo, err := account.GetMiddleUserInfo(c)
	if err != nil {
		response.ResponseJsonFail(c, response.Response{
			Code:    response.ErrorCode,
			Message: err.Error(),
		})
		return
	}
	// 获取所需的消息列表
	messageHistoryList, err := message.GetMessageHistoryLogList(inputData.MessageType,userInfo.Id)
	if err != nil {
		response.ResponseJsonFail(c, response.Response{
			Code:    response.ErrorCode,
			Message: err.Error(),
		})
		return
	}
	response.ResponseJsonOk(c, response.Response{
		Code:    response.SuccessCode,
		Message: "success",
		Data:    messageHistoryList,
	})
	return
}
